package myBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.*;

/**
 * Created by Administrator on 2018/6/10.
 */
    public class ShowImageServlet extends HttpServlet {

        private static final String JPG="image/jpeg;charset=GB2312";

        /**
         * get方法
         */
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            // 本地文件路径
            String filePath = "H:\\dev\\sctu-javaweb-2018-1\\1606101086姚剑test\\web\\image\\838103.jpg";
            File file = new File(filePath);
            // 获取输出流
            OutputStream outputStream = response.getOutputStream();
            FileInputStream fileInputStream = new FileInputStream(file);
            // 读数据
            byte[] data = new byte[fileInputStream.available()];
            fileInputStream.read(data);
            fileInputStream.close();
            // 回写
            response.setContentType(JPG);
            outputStream.write(data);
            outputStream.flush();
            outputStream.close();
        }
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {

        }
    }



